/*
 *
 *
 *
 *
 *
 *
 */

package palidino76.rs2.io.packets;

import palidino76.rs2.*;
import palidino76.rs2.player.*;
import palidino76.rs2.npcs.*;
import palidino76.rs2.util.Misc;
import palidino76.rs2.player.skills.*;
import palidino76.rs2.player.items.PlayerItems;
import palidino76.rs2.io.packets.ItemOption3;

public class OptionClicking {

	Player player;

	/**
	 * Handles the option clicking (Interface)
	 * @param player the player which the constructor should be created for.
	 */
	public OptionClicking(Player player) {
		this.player = player;
		/**
		 * Stream methods for packet 63
		 */
		int somejunk = player.stream.readUnsignedWord();
		player.optionId = player.stream.readSignedWordBigEndian();
		int interfaceId = player.stream.readUnsignedWord();
		/**
		 * Calls PlayerFletching's class constructor
		 */
		PlayerFletching fletch = new PlayerFletching(player);
		PlayerItems pi = new PlayerItems();
		ItemOption3 io3 = new ItemOption3();
		NPC n = Server.engine.npcs[player.clickId];

		if (player.optionId <= 0)
			return;

		switch (player.optionId) {

			case 16: //Option one
				if (player.fletchType == 1) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(1);
					fletch.setDeletedItem(1511);
					fletch.setItemAdded(48);
					fletch.setExperienceReceived(120);
				}
			break;

			case 15: //Option five
				if (player.fletchType == 1) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(5);
					fletch.setDeletedItem(1511);
					fletch.setItemAdded(48);
					fletch.setExperienceReceived(120);
				}
			break;

			case 14: //Option ten
				if (player.fletchType == 1) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(10);
					fletch.setDeletedItem(1511);
					fletch.setItemAdded(48);
					fletch.setExperienceReceived(120);
				}
			break;

			case 13: //Option X
				if (player.fletchType == 1) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(27);
					fletch.setDeletedItem(1511);
					fletch.setItemAdded(48);
					fletch.setExperienceReceived(120);
				}
			break;

			case 12: //Option one
				if (player.fletchType == 1) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(1);
					fletch.setDeletedItem(1511);
					fletch.setItemAdded(50);
					fletch.setExperienceReceived(80);
				}
			break;

			case 11: //Option five
				if (player.fletchType == 1) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(5);
					fletch.setDeletedItem(1511);
					fletch.setItemAdded(50);
					fletch.setExperienceReceived(80);
				}
				if (player.fletchType == 2) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(1);
					fletch.setDeletedItem(1521);
					fletch.setItemAdded(56);
					fletch.setExperienceReceived(890);
				}
				if (player.fletchType == 6) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(1);
					fletch.setDeletedItem(1513);
					fletch.setItemAdded(70);
					fletch.setExperienceReceived(890);
				}
			break;

			case 10: //Option ten
				if (player.fletchType == 1) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(10);
					fletch.setDeletedItem(1511);
					fletch.setItemAdded(50);
					fletch.setExperienceReceived(80);
				}
				if (player.fletchType == 2) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(5);
					fletch.setDeletedItem(1521);
					fletch.setItemAdded(56);
					fletch.setExperienceReceived(890);
				}
				if (player.fletchType == 6) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(5);
					fletch.setDeletedItem(1513);
					fletch.setItemAdded(70);
					fletch.setExperienceReceived(890);
				}
			break;

			case 9: //Option X
				if (player.fletchType == 1) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(27);
					fletch.setDeletedItem(1511);
					fletch.setItemAdded(50);
					fletch.setExperienceReceived(80);
				}
				if (player.fletchType == 2) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(10);
					fletch.setDeletedItem(1521);
					fletch.setItemAdded(56);
					fletch.setExperienceReceived(890);
				}
				if (player.fletchType == 6) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(10);
					fletch.setDeletedItem(1513);
					fletch.setItemAdded(70);
					fletch.setExperienceReceived(890);
				}
			break;

			case 8: //Option one
				if (player.fletchType == 1) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(1);
					fletch.setDeletedItem(1511);
					pi.addItem(player, 52, 5);
					fletch.setExperienceReceived(35);
				}
				if (player.fletchType == 2) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(27);
					fletch.setDeletedItem(1521);
					fletch.setItemAdded(56);
					fletch.setExperienceReceived(890);
				}
				if (player.fletchType == 6) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(27);
					fletch.setDeletedItem(1513);
					fletch.setItemAdded(70);
					fletch.setExperienceReceived(890);
				}
				if (player.NpcWanneTalk == 10000) {
					player.NpcWanneTalk += 1;
					player.NpcDialogueSend = false;
				} else {
					player.NpcWanneTalk = 0;
					player.NpcDialogue = 0;
					player.NpcDialogueSend = false;
					player.frames.removeChatboxInterface(player);	
				}
			break;

			case 7: //Option five
				if (player.fletchType == 1) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(5);
					fletch.setDeletedItem(1511);
					pi.addItem(player, 52, 5);
					fletch.setExperienceReceived(35);
				}
				if (player.fletchType == 2) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(1);
					fletch.setDeletedItem(1521);
					fletch.setItemAdded(54);
					fletch.setExperienceReceived(180);
				}
				if (player.fletchType == 6) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(1);
					fletch.setDeletedItem(1513);
					fletch.setItemAdded(72);
					fletch.setExperienceReceived(890);
				}
				if (player.NpcWanneTalk == 10000) {
					player.NpcWanneTalk += 1;
					player.NpcDialogueSend = false;
				} else if (player.NpcWanneTalk == 2249) {
					player.NpcWanneTalk = 2252;
					player.NpcDialogueSend = false;
				} else if (player.NpcWanneTalk == 968) {
					player.NpcWanneTalk += 1;
					player.NpcDialogueSend = false;
				} else {
					player.NpcWanneTalk = 0;
					player.NpcDialogue = 0;
					player.NpcDialogueSend = false;
					player.frames.removeChatboxInterface(player);	
				}
			break;

			case 6: //Option ten
				if (player.Cooking == true) {
					player.cookAmount = 1;
					player.Cook(player, player.cookXP, player.cookID, player.cookGet, player.cookName);
					player.frames.removeShownInterface(player);
					player.frames.removeChatboxInterface(player);
				}
				if (player.fletchType == 1) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(10);
					fletch.setDeletedItem(1511);
					pi.addItem(player, 52, 5);
					fletch.setExperienceReceived(35);
				}
				if (player.fletchType == 2) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(5);
					fletch.setDeletedItem(1521);
					fletch.setItemAdded(54);
					fletch.setExperienceReceived(180);
				}
				if (player.fletchType == 6) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(5);
					fletch.setDeletedItem(1513);
					fletch.setItemAdded(72);
					fletch.setExperienceReceived(890);
				}
			break;

			case 5: //Option X
					player.destroyItemInt = 0;
					
			/*	if (player.GN == 1 && player.ROD == 0 && player.AOG == 0) {//GN kbd
					player.frames.sendMessage(player, "You teleport outside the KBD lair.");
					player.teleportTo(3067, 10257, 0, 4, 0, 714, 715, 308, 0, -1, 0);
					player.GN = 0;
					player.disconnected[0] = false;
				}
				if (player.GN == 0 && player.ROD == 0 && player.AOG == 1) {//AOG catherby
					player.frames.sendMessage(player, "You teleport to Catherby.");
					player.teleportTo(2836, 3437, 0, 4, 0, 714, 715, 308, 0, -1, 0);
					player.AOG = 0;
					player.disconnected[0] = false;
				}
				if (player.ROD == 1 && player.GN == 0 && player.AOG == 0) { //ROD castlewars
					player.frames.sendMessage(player, "You teleport to CastleWars.");
					player.teleportTo(2442, 3090, 0, 4, 0, 8939, 8941, 1576, 0, 1577, 0);
					player.ROD = 0;
					player.disconnected[0] = false;
				}
			*/
				if (player.NpcWanneTalk == 5479 && player.StraightChamp == 150) {
					player.StraightChampComplete();
				}
				if (player.Cooking == true) {
					player.cookAmount = 5;
					player.Cook(player, player.cookXP, player.cookID, player.cookGet, player.cookName);
					player.frames.removeShownInterface(player);
					player.frames.removeChatboxInterface(player);
				}
				if (player.fletchType == 1) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(27);
					fletch.setDeletedItem(1511);
					pi.addItem(player, 52, 5);
					fletch.setExperienceReceived(35);
				}
				if (player.fletchType == 2) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(10);
					fletch.setDeletedItem(1521);
					fletch.setItemAdded(54);
					fletch.setExperienceReceived(180);
				}
				if (player.fletchType == 6) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(10);
					fletch.setDeletedItem(1513);
					fletch.setItemAdded(72);
					fletch.setExperienceReceived(890);
				}

				if (player.NpcWanneTalk == 2244 || player.NpcWanneTalk == 2245 || player.NpcWanneTalk == 2247 || player.NpcWanneTalk == 961 || player.NpcWanneTalk == 961 || player.NpcWanneTalk == 1696 || player.NpcWanneTalk == 966) {
					player.NpcWanneTalk += 1;
					player.NpcDialogueSend = false;
				} else if (player.NpcWanneTalk == 1597) {
					player.NpcWanneTalk = 1598;
					player.NpcDialogueSend = false;
				} else if (player.NpcWanneTalk == 2248) {
					player.NpcWanneTalk = 2252;
					player.NpcDialogueSend = false;
				} else if (player.NpcWanneTalk == 5483) {
					player.NpcWanneTalk = 5484;
					player.NpcDialogueSend = false;
				} else if (player.NpcWanneTalk == 5484) {
					player.NpcWanneTalk = 5485;
					player.NpcDialogueSend = false;
				} else if (player.NpcWanneTalk == 5485) {
					player.NpcWanneTalk = 5486;
					player.NpcDialogueSend = false;
				} else if (player.NpcWanneTalk == 5486) {
					player.NpcWanneTalk = 5487;
					player.NpcDialogueSend = false;
				} else if (player.NpcWanneTalk == 5480) {
					player.NpcWanneTalk = 5481;
					player.NpcDialogueSend = false;
				} else if (player.NpcWanneTalk == 5480 && player.StraightChamp > 999) {
					player.NpcWanneTalk = 5481;
					player.NpcDialogueSend = false;
				} else if (player.NpcWanneTalk == 5481) {
					player.NpcWanneTalk = 5482;
					player.NpcDialogueSend = false;
				} else if (player.NpcWanneTalk == 5478) {
					player.NpcWanneTalk = 5479;
					player.NpcDialogueSend = false;
				} else if (player.NpcWanneTalk == 2249) {
					player.NpcWanneTalk = 2252;
					player.NpcDialogueSend = false;
				} else if (player.NpcWanneTalk == 2252) {
					player.NpcWanneTalk = 2246;
					player.NpcDialogueSend = false;
				} else if (player.NpcWanneTalk == 1698) {
					player.NpcWanneTalk = 1699;
					player.NpcDialogueSend = false;
				} else if (player.NpcWanneTalk == 1699) {
					player.NpcWanneTalk = 1700;
					player.NpcDialogueSend = false;
				} else if (player.NpcWanneTalk == 963) {
					player.NpcWanneTalk = 0;
					player.NpcDialogue = 0;
					player.NpcDialogueSend = false;
					player.surgeonTimer = 5;
					n.requestAnim(881, 0);
				} else if (player.NpcWanneTalk == 962) {
				    if (player.getLevelForXP(3) >= 99) {
					player.NpcWanneTalk = 968;
					player.NpcDialogueSend = false;
				    } else {
					player.NpcWanneTalk = 971;
					player.NpcDialogueSend = false;
				    }
				} else {
					player.NpcWanneTalk = 0;
					player.NpcDialogue = 0;
					player.NpcDialogueSend = false;
					player.frames.removeChatboxInterface(player);	
				}
			break;

			case 4:
			/*	if (player.GN == 1 && player.ROD == 0 && player.AOG == 0) {//GN god wars
					player.frames.sendMessage(player, "You teleport to GodWars. <col=ff0000>You have been warned!");
					player.teleportTo(2882, 5310, 2, 4, 0, 714, 715, 308, 0, -1, 0);
					player.frames.showInterface(player, 327);
					player.frames.setOverlay(player, 601);
					player.GN = 0;
					player.disconnected[0] = false;
				}
				if (player.GN == 0 && player.ROD == 0 && player.AOG == 1) {//AOG edgeville
					player.frames.sendMessage(player, "You teleport to Edgeville.");
					player.teleportTo(3088, 3494, 0, 4, 0, 714, 715, 308, 0, -1, 0);
					player.AOG = 0;
					player.disconnected[0] = false;
				}
				if (player.ROD == 1 && player.GN == 0 && player.AOG == 0) {//ROD shantay pass
					player.frames.sendMessage(player, "You teleport to the Shantay Pass.");
					player.teleportTo(3306, 3120, 0, 4, 0, 8939, 8941, 1576, 0, 1577, 0);
					player.ROD = 0;
					player.disconnected[0] = false;
				}
			*/
				if (player.fletchType == 2) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(27);
					fletch.setDeletedItem(1521);
					fletch.setItemAdded(54);
					fletch.setExperienceReceived(180);
				}
				if (player.fletchType == 6) {
					fletch.setFletching(true);
					fletch.setFletchingDelay(2);
					fletch.setFletchingAmount(27);
					fletch.setDeletedItem(1513);
					fletch.setItemAdded(72);
					fletch.setExperienceReceived(890);
				}
				if (player.optionArray[0]) {
					player.frames.removeOverlay(player);
				}
				if (player.NpcWanneTalk == 2246) {
					player.NpcDialogueSend = false;
					player.NpcWanneTalk = 0;
					player.frames.removeOverlay(player);	
				}
				if (player.NpcWanneTalk == 962) {
					player.NpcDialogueSend = false;
					player.NpcWanneTalk = 966;	
				}
				if (player.destroyItemInt > 0) {
					Server.engine.playerItems.deleteItem(player, player.destroyItemInt, Server.engine.playerItems.getItemSlot(player, player.destroyItemInt), 1);
					player.destroyItemInt = 0;
				}					
			break;

			case 2: 
			    if (player.optionArray[0]) {
				player.requestAnim(6299, 0);
				player.requestGFX(1062, 0);
				player.frames.setTab(player, 79, 192);
				player.frames.removeOverlay(player);
				player.removeRunes("spellbookswap");
				player.switchBackTimer = 15;
			    }
			/*	if (player.GN == 0 && player.ROD == 0 && player.AOG == 1) {//AOG agility course
					player.frames.sendMessage(player, "You teleport to the Agility Course.");
					player.teleportTo(2480, 3436, 0, 4, 0, 714, 715, 308, 0, -1, 0);
					player.AOG = 0;
					player.disconnected[0] = false;
				}
				if (player.GN == 1 && player.ROD == 0 && player.AOG == 0) {//GN warriors guild
					player.frames.sendMessage(player, "You teleport to the Warriors Guild.");
					player.teleportTo(2880, 3546, 0, 4, 0, 714, 715, 308, 0, -1, 0);
					player.GN = 0;
					player.disconnected[0] = false;
				}
				if (player.ROD == 1 && player.GN == 0 && player.AOG == 0) {//ROD duel arena
					player.frames.sendMessage(player, "You teleport to the Duel Arena.");
					player.teleportTo(3374 + Misc.random(2), 3275 + Misc.random(2), 0, 4, 0, 8939, 8941, 1576, 0, 1577, 0);
					player.frames.showInterface(player, 627);
					player.ROD = 0;
					player.disconnected[0] = false;
				}
			*/
				if (player.NpcWanneTalk == 1598) {
					player.NpcDialogueSend = false;
					player.NpcWanneTalk = 1599;	
				}
				if (player.NpcWanneTalk == 5479 && player.StraightChamp > 999) {
					player.NpcDialogueSend = false;
					player.NpcWanneTalk = 5480;	
				}
				if (player.NpcWanneTalk == 5481 && player.StraightChamp > 999) {
					player.NpcDialogueSend = false;
					player.chatboxInterfaceId = -1;
					player.viewings = 1;
					player.shopid = 3;
					player.frames.showInterface(player, 278);
					player.frames.setItems(player, 278, 89, 94, player.shop3, player.shop3n);
					player.frames.setString(player, "                                       Champion's Guild Trades", 278, 88);
				}
				if (player.NpcWanneTalk == 5482) {
					player.NpcDialogueSend = false;
					player.NpcWanneTalk = 5483;	
				}
				if (player.NpcWanneTalk == 5479) {
					player.NpcDialogueSend = false;
					player.NpcWanneTalk = 5480;	
				}
				if (player.NpcWanneTalk == 2246) {
					player.NpcDialogueSend = false;
					player.NpcWanneTalk += 1;	
				}
				if (player.NpcWanneTalk == 1700) {
					player.NpcDialogueSend = false;
					player.NpcWanneTalk += 1;	
				}
				if (player.NpcWanneTalk == 962) {
					player.NpcDialogueSend = false;
					player.NpcWanneTalk += 1;	
				}
				if (player.NpcWanneTalk == 1697) {
					player.NpcDialogueSend = false;
					player.NpcWanneTalk += 1;	
				}

				if (player.NpcWanneTalk == 969) {
					player.NpcDialogueSend = false;
					player.NpcWanneTalk = 0;
					player.frames.removeOverlay(player);		
				}
			break;

			case 3:
			/*	if (player.GN == 0 && player.ROD == 0 && player.AOG == 1) {//AOG grandexchange
					player.frames.sendMessage(player, "You teleport to the GrandExchange.");
					player.teleportTo(3165, 3472, 0, 4, 0, 714, 715, 308, 0, -1, 0);
					player.AOG = 0;
					player.disconnected[0] = false;
				}
				if (player.GN == 1 && player.ROD == 0 && player.AOG == 0) {//GN bounty hunter
					player.frames.sendMessage(player, "You teleport to BountyHunter.");
					player.teleportTo(3178, 3683, 0, 4, 0, 714, 715, 308, 0, -1, 0);
					player.GN = 0;
					player.disconnected[0] = false;
				}
				if (player.ROD == 1 && player.GN == 0 && player.AOG == 0) {//ROD fight pits
					player.frames.sendMessage(player, "You teleport to the Fight Pits.");
					player.teleportTo(2399, 5178, 0, 4, 0, 8939, 8941, 1576, 0, 1577, 0);
					player.ROD = 0;
					player.disconnected[0] = false;
				}
			*/
				if (player.Cooking == true) {
					player.cookAmount = 28;
					player.Cook(player, player.cookXP, player.cookID, player.cookGet, player.cookName);
					player.frames.removeShownInterface(player);
					player.frames.removeChatboxInterface(player);
				}
			    if (player.optionArray[0]) {
				player.requestAnim(6299, 0);
				player.requestGFX(1062, 0);
				player.frames.setTab(player, 79, 193);
				player.frames.removeOverlay(player);
				player.removeRunes("spellbookswap");
				player.switchBackTimer = 15;
			    }
				if (player.NpcWanneTalk == 2246) {
					player.NpcDialogueSend = false;
					player.NpcWanneTalk = 2249;	
				}
				if (player.NpcWanneTalk == 1700) {
					player.NpcDialogueSend = false;
					player.NpcWanneTalk = 1702;	
				}
				if (player.NpcWanneTalk == 962) {
					player.NpcDialogueSend = false;
					player.NpcWanneTalk = 965;	
				}
				if (player.NpcWanneTalk == 969) {
				  if (Server.engine.playerItems.freeSlotCount(player) > 1) {
				    if (Server.engine.playerItems.haveItem(player, 995, 99000)) {
					player.NpcDialogueSend = false;
					player.NpcWanneTalk += 1;
					Server.engine.playerItems.deleteItem(player, 995, Server.engine.playerItems.getItemSlot(player, 995), 99000);
					Server.engine.playerItems.addItem(player, 9769, 1);
					Server.engine.playerItems.addItem(player, 9770, 1);
				    } else {
					player.NpcDialogueSend = false;
					player.NpcWanneTalk = 973;
				    }
				  } else {
					player.NpcDialogueSend = false;
					player.NpcWanneTalk = 972;
				  }
				}
			break;
		}
		player.optionArray[0] = false;
		player.frames.removeChatboxInterface(player);
		System.out.println("option type: "+player.optionId);
	}

}